<template>
  <div>
    <a-card :bordered="false" class="table-card">
      <a-row>
        <a-col :span="12">
          <a-row>
            <a-col :span="24">
              <div class="table-page-search-wrapper">
                <a-descriptions
                  title="考核基本信息"
                  bordered
                  size="middle"
                  :column="1"
                  :labelStyle="{ justifyContent: 'flex-end', minWidth: 100 }"
                >
                  <a-descriptions-item label="考核标题">
                    {{ assessDeptInfo.assessTitle }}
                  </a-descriptions-item>
                  <a-descriptions-item label="发布时间">
                    {{ assessDeptInfo.endTime }}
                  </a-descriptions-item>
                  <a-descriptions-item label="截止时间">
                    {{ assessDeptInfo.endTime }}
                  </a-descriptions-item>
                  <a-descriptions-item label="考核对象">
                    {{ assessDeptInfo.deptName }}
                  </a-descriptions-item>
                  <a-descriptions-item label="考核类型">
                    <a-tag color="orange">日常考核</a-tag>
                  </a-descriptions-item>
                  <a-descriptions-item label="考核状态">
                    <a-tag color="#2db7f5">
                      {{ statusOptionsFormat(assessDeptInfo.status) }}
                    </a-tag>
                  </a-descriptions-item>
                  <a-descriptions-item
                    label="考核得分"
                    v-if="assessDeptInfo.status == '3'"
                  >
                    <a style="color: #f50; font-size: 14px; font-weight: 400">{{
                      assessDeptInfo.assessScore
                    }}</a>
                  </a-descriptions-item>
                </a-descriptions>
              </div>
            </a-col>

            <a-col :span="24">
              <div class="table-page-search-wrapper">
                <a-descriptions
                  title="考核项目详情"
                  bordered
                  size="middle"
                ></a-descriptions>
                <advance-table
                  title=" "
                  :pagination="{
                    current: queryParam.pageNum,
                    pageSize: queryParam.pageSize,
                    total: total,
                    showSizeChanger: true,
                    showLessItems: true,
                    showQuickJumper: true,
                    showTotal: (total, range) =>
                      `第 ${range[0]}-${range[1]} 条，总计 ${total} 条`,
                    onChange: changeSize,
                    onShowSizeChange: onShowSizeChange,
                  }"
                  tableKey="base-bizAssessDetailsInfo-index-table"
                  rowKey="id"
                  size="middle"
                  @refresh="getList"
                  :columns="columns"
                  :data-source="bizAssessDetailsInfoList"
                  :loading="loading"
                  :format-conditions="true"
                  :row-selection="{
                    selectedRowKeys: selectedRowKeys,
                    onChange: onSelectChange,
                  }"
                >
                  <span slot="assessItem" slot-scope="{ record }">
                    {{ assessItemFormat(record) }}
                  </span>

                  <span slot="operation" slot-scope="{ text, record }">
                    <a @click="handleGetDetails(record)"> 查看 </a>
                  </span>
                  <span slot="rowindex" slot-scope="{ index }">
                    {{ index + 1 }}
                  </span>
                   <span slot="assessScoreStatus" slot-scope="{ record }">
                   <a-tag v-if="record.assessScore" color="#2db7f5">已评分</a-tag>
                   <a-tag v-else color="#f50">未评分</a-tag></a-tag>
                  </span>
                </advance-table>
              </div>
            </a-col>
          </a-row>
        </a-col>
        <a-col
          :span="12"
          style="border-left: 1.5px solid #ecedee; height: calc(100vh - 17vh)"
        >
          <a-row>
            <a-col :span="24">
              <div class="table-page-search-wrapper">
                <a-descriptions
                  title="考核标准详情"
                  bordered
                  size="middle"
                  :column="1"
                  :labelStyle="{ justifyContent: 'flex-end', minWidth: 100 }"
                >
                  <a-descriptions-item label="考核项目">
                    {{ assessItemFormat(assessDeptDetails) }}
                  </a-descriptions-item>
                  <a-descriptions-item label="考核指标">
                    <a-textarea
                      v-model="assessDeptDetails.assessTitle"
                      disabled
                      :rows="3"
                    ></a-textarea>
                  </a-descriptions-item>
                  <a-descriptions-item label="考核标准">
                    <a-textarea
                      v-model="assessDeptDetails.assessContent"
                      disabled
                      :rows="3"
                    ></a-textarea>
                  </a-descriptions-item>
                  <a-descriptions-item label="评分标准">
                    <a-textarea
                      v-model="assessDeptDetails.assessMark"
                      disabled
                      :rows="3"
                    ></a-textarea>
                  </a-descriptions-item>
                  <a-descriptions-item label="最高得分">
                    {{ assessDeptDetails.assessMaxScore }}
                  </a-descriptions-item>
                  <a-descriptions-item label="资料列表">
                    <!-- <a-upload :file-list="fileList"> </a-upload> -->
                    <span v-for="(item, index) in fileList" :key="index">
                      <a target="_blank" :href="item.url">{{ item.name }} </a>
                    </span>
                  </a-descriptions-item>
                  <a-descriptions-item label="备注">
                    <a-textarea
                      v-model="assessDeptDetails.remark"
                      disabled
                      :rows="3"
                    ></a-textarea>
                  </a-descriptions-item>
                  <a-descriptions-item
                    label="考核项得分"
                    v-if="assessDeptInfo.status == '2'"
                  >
                    <a-input-number
                      v-model="assessDeptDetails.assessScore"
                      :min="0"
                      :max="assessDeptDetails.assessMaxScore"
                      v-if="assessDeptDetails.id"
                      style="width: 120px"
                    ></a-input-number>
                  </a-descriptions-item>

                  <a-descriptions-item
                    label="该项得分"
                    v-if="assessDeptInfo.status == '3'"
                  >
                    <a style="color: #f50; font-size: 14px; font-weight: 400">{{
                      assessDeptDetails.assessScore
                    }}</a>
                  </a-descriptions-item>
                </a-descriptions>
              </div>
            </a-col>
            <a-col :span="24" style="text-align: center; margin-top: 20px">
              <a-button
                v-if="assessDeptDetails.id&&assessDeptInfo.status == '2'"
                type="primary"
                @click="handlerSaveDetailsScore"
                >保存该项评分</a-button
              >
            </a-col>
          </a-row>
        </a-col>
      </a-row>

      <!-- 增加 -->
    </a-card>
  </div>
</template>
<script>
import {
  listBizAssessToDeptDetails,
  updateBizAssessToDeptDetails,
} from "@/api/biz/bizAssessToDeptDetails";
import {
  addBizAssessToDeptDetailsFile,
  delBizAssessToDeptDetailsFile,
  listBizAssessToDeptDetailsFile,
} from "@/api/biz/bizAssessToDeptDetailsFile";
import AdvanceTable from "@/components/pt/table/AdvanceTable";
export default {
  name: "BizAssessDetailsInfo",
  components: {
    AdvanceTable,
  },
  props: {
    assessDeptInfo: {
      type: Object,
    },
  },
  data() {
    return {
      showAddModal: false,
      showEditModal: false,
      // 遮罩层
      loading: true,
      fileList: [],
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 6 },
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 考核详情表格数据
      bizAssessDetailsInfoList: [],
      // 考核项目字典
      assessItemOptions: [],
      statusOptions: [],
      assessDeptDetails: [],
      // 查询参数
      queryParam: {
        pageNum: 1,
        pageSize: 10,
      },
      columns: [
        {
          title: "序号",
          dataIndex: "rowindex",
          ellipsis: true,
          align: "center",
          width: "6%",
          scopedSlots: { customRender: "rowindex" },
        },
        {
          title: "考核项目",
          dataIndex: "assessItem",
          scopedSlots: { customRender: "assessItem" },
          align: "center",
          width: "10%",
        },
        {
          title: "考核指标",
          dataIndex: "assessTitle",
          ellipsis: true,
          align: "center",
          width: "20%",
        },
        {
          title: "考核标准",
          dataIndex: "assessContent",
          align: "center",
          ellipsis: true,
          width: "20%",
        },
        {
          title: "评分标准",
          dataIndex: "assessMark",
          align: "center",
          width: "15%",
          ellipsis: true,
        },
        {
          title: "最高分",
          dataIndex: "assessMaxScore",
          align: "right",
          width: "10%",
        },
        {
          title: "该项得分",
          dataIndex: "assessScore",
          align: "right",
          width: "10%",
        },
        {
          title: "状态",
          dataIndex: "assessScoreStatus",
          align: "right",
          width: "10%",
          scopedSlots: { customRender: "assessScoreStatus" },
        },
        {
          title: "操作",
          dataIndex: "operation",
          align: "center",
          width: "10%",
          scopedSlots: { customRender: "operation" },
        },
      ],
    };
  },
  created() {
    // this.getList(this.assessDeptInfo.id);
    this.getDicts("assess_item").then((response) => {
      this.assessItemOptions = response.data;
    });
    this.getDicts("assess_info_status").then((response) => {
      this.statusOptions = response.data;
    });
  },
  watch: {
    assessDeptInfo: {
      handler(val) {
        this.getList(this.assessDeptInfo.id);
      },
      deep: true,
    },
  },
  methods: {
    handlerSaveDetailsScore() {
      updateBizAssessToDeptDetails({
        id: this.assessDeptDetails.id,
        assessScore: this.assessDeptDetails.assessScore,
      }).then((response) => {
        this.$message.success("保存成功", 3);
      });
    },
    uploadCompleteFile(item, items) {
      console.log(("item", item, items));
      addBizAssessToDeptDetailsFile({
        assessDeptDetailsId: this.assessDeptDetails.id,
        fileName: item.fileName,
        fileUrl: item.url,
      }).then((response) => {
        this.$message.success("上传成功", 3);
      });
    },
    handlerRemoveFile(file) {
      console.log("file", file);
      delBizAssessToDeptDetailsFile({
        fileUrl: file.url,
        fileName: file.name,
      }).then((response) => {
        this.$message.success("删除成功", 3);
      });
    },

    /** 查询考核详情列表 */
    getList(assessdeptId) {
      this.loading = true;
      // this.queryParam.assessId = assessId;
      // this.queryParam.deptId = this.assessDeptInfo.deptId;
      this.queryParam.assessDeptId = assessdeptId;
      // this.queryParam.assessDept = this.form.assessDept;
      listBizAssessToDeptDetails(this.queryParam).then((response) => {
        this.bizAssessDetailsInfoList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 考核项目字典翻译
    assessItemFormat(row) {
      if (row.assessItem) {
        return this.selectDictLabel(this.assessItemOptions, row.assessItem);
      } else {
        return "";
      }
    },
    // 考核项目字典翻译
    statusOptionsFormat(status) {
      if (status) {
        return this.selectDictLabel(this.statusOptions, status);
      } else {
        return "";
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
      };
      this.handleQuery();
    },
    /** 翻页操作 */
    onShowSizeChange(current, pageSize) {
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSizeChange(current, size) {
      this.queryParam.pageNum = 1;
      this.queryParam.pageSize = size;
      this.getList();
    },
    /** 翻页操作 */
    changeSize(current, pageSize) {
      this.queryParam.pageNum = current;
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
      this.ids = this.selectedRows.map((item) => item.id);
      this.single = selectedRowKeys.length !== 1;
      this.multiple = !selectedRowKeys.length;
    },
    /** 查询折叠和展开操作 */
    toggleAdvanced() {
      this.advanced = !this.advanced;
    },
    handleAdd() {
      this.showAddModal = true;
      this.$nextTick(() => this.$refs.bizAssessDetailsInfoAddForm.handleAdd());
    },
    handleUpdate(record, ids) {
      this.showEditModal = true;
      this.$nextTick(() =>
        this.$refs.bizAssessDetailsInfoEditForm.handleUpdate(record, ids)
      );
    },
    handleGetDetails(record) {
      this.assessDeptDetails = record;
      listBizAssessToDeptDetailsFile({ assessDeptDetailsId: record.id }).then(
        (response) => {
          this.fileList = response.data.list.map((item) => {
            return {
              name: item.fileName,
              url: item.fileUrl,
              uid: item.id,
              status: "done",
            };
          });
        }
      );
    },
    /** 删除按钮操作 */
  },
};
</script>
<style scoped>
/deep/.table-card {
  min-height: calc(100vh - 128px);
}
</style>
